package cli

import (
	"context"
	"io/ioutil"

	"gitee.com/huanghua_2017/blade/api"
	"gitee.com/huanghua_2017/hggutils/jsonrpc"
)

func GetServerAPI() (api.Server, jsonrpc.ClientCloser, error) {
	addr, err := ioutil.ReadFile("sapi")
	if err != nil {
		return nil, nil, err
	}
	var api api.ServerStruct
	closer, err := jsonrpc.NewMergeClient(context.Background(), "ws://"+string(addr)+"/rpc/v0", "Blade", []interface{}{&api.CommonStruct.Internal}, nil)
	if err != nil {
		return nil, nil, err
	}
	return &api, closer, nil
}
